﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RR57_2Response", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR572Response))]
    public class RR572ResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IRR572Response clazz;
        
        public RR572ResponseSerializer(IRR572Response clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Isik");
            if (clazz.Isik!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute(">>>RR57_2Response>Isik>Isik", "http://producers.rr.xtee.riik.ee/producer/rr", clazz.Isik.Count);
                for (int x = 0; ((clazz.Isik != null) 
                            && (x < clazz.Isik.Count)); x = (x + 1)) {
                    if (clazz.Isik[x]!=null) {
                        Writer.WriteStartElement("Isik");
                        global::Xtee.Core.SerializationMetadata metaIsik = this.GetMetaData(clazz.Isik[x]);
                        Writer.WriteTypeAttribute(metaIsik.TypeQualifiedName.Namespace, metaIsik.TypeQualifiedName.Name);
                        metaIsik.NewSerializer(clazz.Isik[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isik");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Isik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR57_2Response>Isik");
                }
                clazz.Isik = new System.Collections.Generic.List<RR572Response.IIsikType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("Isik");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "Isik")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>RR57_2Response>Isik>Isik");
                        }
                        global::Xtee.Core.SerializationMetadata metaIsik = this.GetMetaData<RR572Response.IIsikType>(Reader, ">>>RR57_2Response>Isik>Isik", "http://producers.rr.xtee.riik.ee/producer/rr");
                        RR572Response.IIsikType item = metaIsik.NewEntity<RR572Response.IIsikType>();
                        clazz.Isik.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("Isik");
                            metaIsik.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR57_2Response>Isik", Reader.LocalName);
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>RR57_2Response>Isik>Isik", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR572Response.IsikType))]
        public class IsikTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected RR572Response.IIsikType clazz;
            
            public IsikTypeSerializer(RR572Response.IIsikType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                Writer.WriteStartElement("Isik.Isikukood");
                if (clazz.IsikIsikukood!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikIsikukood))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikIsikukood");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isik.Perenimi");
                if (clazz.IsikPerenimi!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikPerenimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikPerenimi");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isik.Eesnimi");
                if (clazz.IsikEesnimi!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikEesnimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikEesnimi");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isik.Olek");
                if (clazz.IsikOlek!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikOlek))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikOlek");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isik.Surmakuup");
                if (clazz.IsikSurmakuup!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikSurmakuup))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikSurmakuup");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isik.Riik");
                if (clazz.IsikRiik!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikRiik))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikRiik");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isik.Elukoht");
                if (clazz.IsikElukoht!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikElukoht))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikElukoht");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isik.tanav");
                if (clazz.Isiktanav!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Isiktanav))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isiktanav");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isik.maja");
                if (clazz.Isikmaja!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Isikmaja))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isikmaja");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isik.korter");
                if (clazz.Isikkorter!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Isikkorter))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isikkorter");
                }
                Writer.WriteEndElement();
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="Isik.Isikukood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR57_2Response>Isik>Isik>Isik.Isikukood");
                    }
                    clazz.IsikIsikukood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isik.Isikukood")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR57_2Response>Isik>Isik>Isik.Isikukood", Reader.LocalName);
                }
                if (Reader.LocalName=="Isik.Perenimi") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR57_2Response>Isik>Isik>Isik.Perenimi");
                    }
                    clazz.IsikPerenimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isik.Perenimi")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR57_2Response>Isik>Isik>Isik.Perenimi", Reader.LocalName);
                }
                if (Reader.LocalName=="Isik.Eesnimi") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR57_2Response>Isik>Isik>Isik.Eesnimi");
                    }
                    clazz.IsikEesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isik.Eesnimi")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR57_2Response>Isik>Isik>Isik.Eesnimi", Reader.LocalName);
                }
                if (Reader.LocalName=="Isik.Olek") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR57_2Response>Isik>Isik>Isik.Olek");
                    }
                    clazz.IsikOlek = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isik.Olek")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR57_2Response>Isik>Isik>Isik.Olek", Reader.LocalName);
                }
                if (Reader.LocalName=="Isik.Surmakuup") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR57_2Response>Isik>Isik>Isik.Surmakuup");
                    }
                    clazz.IsikSurmakuup = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isik.Surmakuup")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR57_2Response>Isik>Isik>Isik.Surmakuup", Reader.LocalName);
                }
                if (Reader.LocalName=="Isik.Riik") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR57_2Response>Isik>Isik>Isik.Riik");
                    }
                    clazz.IsikRiik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isik.Riik")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR57_2Response>Isik>Isik>Isik.Riik", Reader.LocalName);
                }
                if (Reader.LocalName=="Isik.Elukoht") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR57_2Response>Isik>Isik>Isik.Elukoht");
                    }
                    clazz.IsikElukoht = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isik.Elukoht")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR57_2Response>Isik>Isik>Isik.Elukoht", Reader.LocalName);
                }
                if (Reader.LocalName=="Isik.tanav") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR57_2Response>Isik>Isik>Isik.tanav");
                    }
                    clazz.Isiktanav = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isik.tanav")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR57_2Response>Isik>Isik>Isik.tanav", Reader.LocalName);
                }
                if (Reader.LocalName=="Isik.maja") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR57_2Response>Isik>Isik>Isik.maja");
                    }
                    clazz.Isikmaja = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isik.maja")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR57_2Response>Isik>Isik>Isik.maja", Reader.LocalName);
                }
                if (Reader.LocalName=="Isik.korter") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR57_2Response>Isik>Isik>Isik.korter");
                    }
                    clazz.Isikkorter = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isik.korter")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR57_2Response>Isik>Isik>Isik.korter", Reader.LocalName);
                }
            }
        }
    }
}
